package com.baoyouqun.domain.Enum;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;

@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ReportTypeEnum {
    SPAM("spam", "垃圾信息"),
    ILLEGAL("illegal", "违法内容"),
    ABUSE("abuse", "辱骂");

    @EnumValue // 标记数据库存储的字段
    private final String code;
    private final String desc;

    ReportTypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 根据 code 解析枚举
    public static ReportTypeEnum fromCode(String code) {
        for (ReportTypeEnum type : values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的举报类型：" + code);
    }
}